<template>
  <div class="page-container">
    <el-tabs
      v-model="activeName1"
      type="border-card"
      @tab-remove="removeTab"
      @tab-add="addTab"
      @tab-change="handleTabChange"
    >
      <el-tab-pane
        v-for="item in seriesList"
        :key="item.SeriesId"
        :name="item.SeriesId"
      >
        <template #label>
          <div class="flex items-center">
            <span>{{ item.SeriesName }}</span>
            <el-icon
              v-if="activeName1 == item.SeriesId"
              class="ml-1"
              @click="handleTurnToAdd"
              ><Plus
            /></el-icon>
          </div>
        </template>
      </el-tab-pane>
      <el-segmented v-model="activeName2" :options="tab2Options" size="large" />
      <hr />
      <template v-if="activeName2 == '订单属性'">
        <DefaultAttrsManageTabPane :key="activeName1" />
      </template>
      <template v-else-if="activeName2 == '计算属性'">
        <CalcAttrsManageTabPane :key="activeName1" />
      </template>
      <template v-else>
        <QuotationAttrsManageTabPane :key="activeName1" />
      </template>
    </el-tabs>
  </div>
</template>
<script setup>
import {
  Plus,
  Refresh,
  Search,
  CirclePlusFilled,
} from "@element-plus/icons-vue";
import { ElMessage } from "element-plus";
import useOrderAttrStore from "../../../../store/modules/orderAttrs";
import { onBeforeMount, onMounted } from "vue";
import { useRouter } from "vue-router";
import { seriesQueryApi } from "@/api/order/series/index.js";
import DefaultAttrsManageTabPane from "./components/DefaultAttrsManageTabPane.vue";
import CalcAttrsManageTabPane from "./components/CalcAttrsManageTabPane.vue";
import QuotationAttrsManageTabPane from "./components/QuotationAttrsManageTabPane.vue";

const orderAttrsStore = useOrderAttrStore();
const router = useRouter();
const data = ref([]);
const queryParams = ref({
  pageNum: 1,
  pageSize: 10,
});
const activeName1 = ref();
const activeName2 = ref("订单属性");
const seriesList = ref([]);
const tab2Options = ref([
  {
    label: "订单属性",
    value: "订单属性",
  },
  {
    label: "计算属性",
    value: "计算属性",
  },
  {
    label: "报价方式",
    value: "报价方式",
  },
]);
watch(
  () => orderAttrsStore.currentProductSeries.SeriesId,
  (val) => {
    if (val) {
      activeName1.value = val;
    }
  },
  { immediate: true }
);
async function getList() {
  const res = await seriesQueryApi();
  seriesList.value = res.Data || [];
  if (!orderAttrsStore.currentProductSeries.SeriesId) {
    if (seriesList.value.length == 0) {
      seriesList.value.push({ SeriesId: 0, SeriesName: "" });
    }
    activeName1.value = seriesList.value[0].SeriesId;
    orderAttrsStore.setCurrentSeries(seriesList.value[0]);
  }
  // 根据SeriesId获取属性列表
  // loading.value = true;
  // loading.value = false;
}
function removeTab() {}
function addTab() {}
function handleTabChange() {
  orderAttrsStore.setCurrentSeries(
    seriesList.value.find((s) => s.SeriesId == activeName1.value)
  );
}
function handleTabClick2() {}
function handleTurnToAdd() {
  router.push({ path: "./product" });
}
onMounted(() => {
  getList();
});
</script>

<style lang="scss">
.page-container {
  margin: 10px;
  padding-bottom: 20px;
  border-radius: 2px;
}
.demo-tabs > .el-tabs__content {
  padding: 32px;
  color: #6b778c;
  font-size: 32px;
  font-weight: 600;
}
.demo-tabs .custom-tabs-label .el-icon {
  vertical-align: middle;
}
.demo-tabs .custom-tabs-label span {
  vertical-align: middle;
  margin-left: 4px;
}
</style>
